package cn.itcast.ks.controller.v1;

import cn.itcast.ks.common.AppHttpCodeEnum;
import cn.itcast.ks.common.ResponseResult;
import cn.itcast.ks.pojo.dtos.AddIntegralDto;
import cn.itcast.ks.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wjs
 * @version 1.0
 * @date 2021/12/5 0005 上午 11:46
 */

@RestController
@RequestMapping("/v1/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/findByClassId")
    public ResponseResult findByClassId() {
        return userService.findByClassId();
    }

    @PostMapping("/addIntegral")
    public ResponseResult addIntegral(@RequestBody AddIntegralDto dto) {
        if (dto == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return userService.addIntegral(dto);
    }

    @GetMapping("/resetGScoreByGroupId/{classId}")
    public ResponseResult resetGScoreByGroupId(@PathVariable Integer classId) {
        if (classId == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return userService.resetGScoreByGroupId(classId);
    }
}
